package nl.hanze.designpatterns.mvc.view;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import nl.hanze.designpatterns.mvc.controller.MainAppGuiController;
import nl.hanze.designpatterns.mvc.controller.MenuBarController;

public class MenuBar extends JMenuBar {
	
	private JMenu fileMenu;
	private JMenu ticketsMenu;
	private JMenu accountMenu;
	private JMenu helpMenu;
	private MenuBarController menuBarController;
		
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MenuBar(MainAppGuiController mainAppGuiController){
		this.init(mainAppGuiController);
		this.addMenuItems();
	}
	
	private void init(MainAppGuiController mainAppGuiController){
		this.menuBarController = new MenuBarController(mainAppGuiController);
		this.fileMenu = new JMenu("File");
		this.ticketsMenu = new JMenu("Tickets");
		this.accountMenu = new JMenu("Profile");
		this.helpMenu = new JMenu("Help");
	}
	
	private void addMenuItems(){
		this.add(fileMenu);
		this.setFileMenuItems();
		
		this.add(ticketsMenu);
		this.setIncidentsMenuItems();
		
		this.add(accountMenu);
		this.setAccountMenu();
		
		this.add(helpMenu);
		this.setHelpMenu();
	}
	
	private void setFileMenuItems(){
		JMenuItem exit = new JMenuItem("Exit");
		
		//add listeners
		exit.addActionListener(this.menuBarController);
		exit.setActionCommand("exit");
		
		//add to menu
		this.fileMenu.add(exit);
		
	}
	
	private void setIncidentsMenuItems(){
		//JMenuItem addIncident = new JMenuItem("New Incident");
		JMenuItem showTickets = new JMenuItem("Show Tickets");
		
		//add listeners
		//addIncident.addActionListener(this.menuBarController);
		showTickets.addActionListener(this.menuBarController);
		showTickets.setActionCommand("showTicketsView");
		
		//add to menu
		//this.incidentsMenu.add(addIncident);
		this.ticketsMenu.add(showTickets);
		
	}
	
	private void setAccountMenu(){
		JMenuItem showProfile = new JMenuItem("Show Profile");
		JMenuItem logOut = new JMenuItem("Logout");
		
		//add listeners
		showProfile.addActionListener(this.menuBarController);
		showProfile.setActionCommand("showProfile");
		
		logOut.addActionListener(this.menuBarController);
		logOut.setActionCommand("logout");
		
		//add to menu
		this.accountMenu.add(showProfile);
		this.accountMenu.addSeparator();
		this.accountMenu.add(logOut);
	}
	
	private void setHelpMenu(){
		JMenuItem qena = new JMenuItem("QenA");
		JMenuItem about = new JMenuItem("About");
		
		//add listeners
		qena.addActionListener(this.menuBarController);
		qena.setActionCommand("display_qena");
		about.addActionListener(this.menuBarController);
		about.setActionCommand("help");
		
		//add to menu
		this.helpMenu.add(qena);
		this.helpMenu.addSeparator();
		this.helpMenu.add(about);
	}

}
